* This file: .\replication\figure_1\figure_1.do

* Source:
	* https://www.oecd-ilibrary.org/economics/household-debt/indicator/english_f03b6469-en
	* Source: OECD National Accounts Statistics: National Accounts at a Glance (https://doi.org/10.1787/f03b6469-en) (OECD 2018a).

clear all
insheet using DP_LIVE_26042021111015319.csv, comma clear

rename location iso3c
kountry iso3c, from(iso3c) to(cown)
rename _COWN ccode
labmask ccode, val(iso3c)
numlabel ccode, add force
tab iso3c if ccode==.

rename time year
isid ccode year

label var value "Total household debt (% of net disposable income)"

gen aid=inlist(ccode,2,20,200,205,210,211,212,220,225,230,235,255,305,325,350,375,380,385,390,395,740,900,920)

keep if aid==1

*tw (connected value year, sort), by(iso3c)

tabstat year if value<., by(ccode) s(min max)
bys ccode (year): keep if _n==1 | _n==_N
tabstat year if value<., by(ccode) s(min max)

drop if inlist(ccode,920,205,212)

tabstat year if value<., by(ccode) s(min max)

bys iso3c (year): gen time=_n
keep ccode iso3c time value
rename value debt
reshape wide debt , i(ccode iso3c) j(time)

graph bar debt1 debt2, ///
	over(iso3c) ///
	scheme(538bw) ///
	legend(pos(6) label(1 "1995") label(2 "2019")) ///
	horizontal ysize(5) xsize(5) ///
	bar(1, color(gs10)) bar(2, color(gs1)) ///
	ytitle(" " "Total household debt (% of net disposable income)") 

graph save   figure_1.gph, replace
graph export figure_1.emf, replace
graph export figure_1.pdf, replace

sum debt1 debt2


